﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		Comment.Validation.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            Comment.Validation.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class Comment {
		public virtual void ValidateForSave ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.Is ( 0 )
				.WithMessage ( "Invalid comment key." );

			BasicValidate ( );
		}

		public virtual void ValidateForDelete ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid comment key" );
		}


		public virtual void ValidateForUpdate ( ) {
			Ensure.That ( Id )
				.Named ( "Id" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid comment key" );

			BasicValidate ( );
		}

		void BasicValidate ( ) {
			Ensure.That ( Name )
				.Named ( "Name" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid comment name." );

			Ensure.That ( Email )
				.Named ( "email" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNull ( )
				.WithMessage ( "Invalid comment email." );

			if ( Parent != null ) {
				Ensure.That ( Parent.Id )
					.Named ( "parent.Id" )
					.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
					.IsGreaterThen ( 0 )
					.WithMessage ( "The parent category Key is invalid." );
			}
		}
	}
}
